package users

import (
	"duanju-mq/pkg/config"
	"duanju-mq/pkg/net/http/gotpsess2"
)

func init() {
	gotpsess2.SetUserSecrets(loadUsers())
	config.OnReload(func() {
		gotpsess2.SetUserSecrets(loadUsers())
	})
}

func loadUsers() map[string]string {
	m := map[string]string{}
	config.Sequence("lib.gotpsess.users", "", func(cfg *config.SeqCfg) {
		name := *cfg.String("name", "", "")
		secret := *cfg.String("secret", "", "")
		m[name] = secret
	})
	return m
}

var Login = gotpsess2.Login
var Get = gotpsess2.GetUser
